home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
answr202.zip
/
ANSWER.ASM
next >
Wrap
Assembly Source File
|
1986-12-14
|
8KB
|
170 lines
;program: ANSWER.COM
;syntax: ANSWER [prompt line]
;author: Frank Schweiger (02/01/86)
; v1.00 original
;history: Brad Berson (12/14/86)
; disassembled using ASMGEN2 (v2.01 - J. Gersbach, J. Damke)
; v2.00 Added uppercase conversion
; v2.01 Added proper cr/lf after return key pressed
; v2.02 Fixed dumb bug in uppercase conversion
;create: MASM ANSWER;
; LINK ANSWER;
; EXE2BIN ANSWER.EXE ANSWER.COM
; DEL ANSWER.OBJ
; DEL ANSWER.EXE
;
;I commented this the best I could, but somewhat tersely, as
RET_NEAR MACRO
DB 0C3H
ENDM
.RADIX 16
LF EQU 0AH
CR EQU 0DH
CODE SEGMENT
ASSUME DS:CODE, SS:CODE, CS:CODE, ES:CODE
ORG $+0100H
BEGIN: MOV SI,80 ;length of cmd_tail PSP to SI
LODSB ;to AX, inc SI to point cmd_tail
AND AX,7F ;make sure length 1..127
JZ KBDIN ;dont print cmd_tail if len=0
MOV DI,AX ;length to DI
ADD DI,SI ;add offset to length cmd_tail
MOV BYTE PTR [DI],24 ;terminate cmd_tail with '$'
MOV DX,SI ;offset cmd_tail to DX
INC DX ;compensate for leading space
MOV AH,9 ;print_string
INT 21 ;dos call
KBDIN: MOV DX,OFFSET BUF_MAX_LEN ;1st byte of buffer is max_len
MOV AH,0A ;for get_buffered_input
INT 21 ;dos call
PUSH DX ;save DX
MOV DL,CR ;
MOV AH,2 ;print CR
INT 21 ;
MOV DL,LF ;
MOV AH,2 ;print LF
INT 21 ;
POP DX ;restore DX
MOV AL,BUF_CON_LEN ;check length of vbl
CMP AL,0 ;more than 0?
JZ DOIT ;skip upcas if 0
CALL UPCAS ;convert input to uppercase
DOIT: CALL FNDENV ;find location of prnt_env
MOV CX,BX ;BX env_size to CX
MOV ES,AX ;AX env_seg to ES
XOR DI,DI ;zero DI for str_srch
XOR AL,AL ;val to search for in AL 0
CLD ;set DF to inc DI in str_srch
SRCH: REPNZ SCASB ;search entire prnt_env
JNZ ERR ;ERR if 0 not found
CMP AL,ES:[DI] ;followed by another 0 (end)?
JZ DOENV ;yes, go modify env, else
MOV DX,DI ;save pntr from str_srch in DX
MOV BP,CX ;save cntr from str_srch in BP
MOV SI,OFFSET ENV_STRING ;looking for 'ANSWER='
MOV CX,7 ;length of 'ANSWER=' to CX
REPZ CMPSB ;compare with env
JZ CHK ;jump if compare successful
MOV DI,DX ;restore pntr fr str_srch to DI
MOV CX,BP ;restore cntr fr str_srch to CX
JMP SHORT SRCH ;search for next 0
CHK: MOV CX,51 ;max len of ANSWER vbl to CX
REPNZ SCASB ;search for and of vbl 0
JNZ ERR ;ERR if 0 not found in 51H tries
MOV SI,DI ;offset end_of_answr +1 to SI
MOV DI,DX ;offset ANSWER in prnt_env to DI
MOV CX,ES ;copy ES
MOV DS,CX ; to DS
MOV CX,BX ;length prnt_env to CX
SUB CX,SI ;CX= length-offset end_of_answr
DUN_1: LODSB ;byte at end_of_answr + 1 to DI,
AND AL,AL ;inc SI.
JZ DOENV ;jump if 0 (end_of_env)
DUN_2: STOSB ;byte at end_of_answr + 1 to
LOOP DUN_3 ;offset of ANSWER=, inc SI,
JMP SHORT ERR ; get next byte in environment
DUN_3: LODSB ;get next byte in environment
AND AL,AL ;is it 0 (end_of_vbl)?
JNZ DUN_2 ;move byte and get next, else
STOSB ;move this byte and check if
LOOP DUN_1 ;end_of_env
ERR: MOV AX,4C01 ;exit with errorlevel 1
INT 21 ;dos call
DOENV: MOV BYTE PTR ES:[DI],0 ;
MOV AX,CS ;move CS
MOV DS,AX ; to DS
MOV AL,BUF_CON_LEN ;buf_con_len to AL (len of vbl)
XOR AH,AH ;zero AH for these additions...
ADD AX,8 ; length of 'ANSWER='
ADD AX,DI ; offset of end_of_answr
CMP AX,BX ;len prnt_env - tot calc length
JNB ERR ;jump if calc gt actual (JA)
MOV SI,OFFSET ENV_STRING ;offset of 'ANSWER=' to SI
MOV CX,7 ;length of 'ANSWER='
REPZ MOVSB ;move 'ANSWER=' to env_tail
MOV SI,OFFSET KBD_BUFFER ;offset of vbl to SI
MOV CL,BUF_CON_LEN ;length of buffer to CX
REPZ MOVSB ;move vbl to end after '='
XOR AX,AX ;word 00 in AX
STOSW ;move word 00 to end_of_vbl
MOV AX,4C00 ;exit with errorlevel 0
INT 21 ;dos call
FNDENV: PUSH ES ;save ES
MOV AX,CS ;move CS
MOV ES,AX ; to ES (point ES to psp)
MOV AX,ES:14 ;psp:14 pntr prnt_psp seg to AX
MOV ES,AX ;prnt_psp seg to ES
MOV AX,ES:2C ;prnt_psp:2c pntr prnt_env seg
AND AX,AX ;unless prnt_env seg is 00
JNZ FNDSIZ ;jump (should always jump)
MOV AX,ES ;
DEC AX ; / ?
MOV ES,AX ; /
ADD AX,ES:3 ; /
ADD AX,2 ; ? /
FNDSIZ: DEC AX ;point ES to prnt_mcb
MOV ES,AX ; (para below prnt_env)
INC AX ;reset AX
MOV BX,ES:3 ;env_size at mcb:3 to BX
SHL BX,1 ;convert BX from
SHL BX,1 ;# paragraphs
SHL BX,1 ;to
SHL BX,1 ;# bytes
POP ES ;restore ES
RET_NEAR ;return
UPCAS: XOR CX,CX
MOV CL,BUF_CON_LEN ;length vbl to convert in CX
MOV BX,OFFSET KBD_BUFFER ;beginning of vbl
TSTCH: MOV AL,[BX] ;character to BX
CMP AL,'a' ;below lower case char?
JB NXTCH ;skip if so
CMP AL,'z' ;above lower case char?
JA NXTCH ;skip if so
AND AL,5F ;mask out bit 5
NXTCH: MOV [BX],AL ;store the character
INC BX ;point to next char
LOOP TSTCH ;do until no more chars
RET_NEAR ;return
BUF_MAX_LEN DB 50
BUF_CON_LEN DB 0
KBD_BUFFER DB 50 DUP(0)
ENV_STRING DB 'ANSWER=VER 2.02'
CODE ENDS
END BEGIN